<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<script type="text/javascript" src="comet4j.js"></script>
<script type="text/javascript" src="jquery-1.11.1.js"></script> 
<script type="text/javascript">
var count = 0;
window.onload = function(){
    // 建立连接，conn 即web.xml中 CometServlet的<url-pattern>
    JS.Engine.start('conn');
    <%  
         //保存用户id到session中
         //session.setAttribute("currentUserId",user.getId().toString());
         session.setAttribute("currentUserId","654321");
    %>  
    // 监听后台某个频道
    JS.Engine.on(
         { 
            // 对应服务端 “频道1” 的值 msgCount
            msgCount : function(msgCount){
                $("#msgCount").html(msgCount);
            },
            // 对应服务端 “频道2” 的值 msgData
            msgData : function(msgData){
            	
            	for (var p in msgData) {
    			    if (msgData.hasOwnProperty(p)) {
    			        var value = msgData[p];
    			        console.log(value.name);
    			        $("#userid").html(value.user_id);
    			        $("#message").html(value.message);
    			        $("#read_status").html(value.read_status);
    			      // console.log(p+","+value);
    			       console.log(msgData);
    			    }
    			}
                
            },
        }
    );
}
</script>

<body>

<!-- 消息数量：<span id="msgCount"></span>
消息数据：<span id="msgData"></span> -->
userid:<span id="userid"></span>
message:<span id="message"></span>
read_status:<span id="read_status"></span>




</body>